home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS01.ADF / C / IBM2Amiga.c < prev    next >
Text File  |  1986-01-09  |  12KB  |  321 lines

  1. Path: puff!uwvax!seismo!gatech!akgua!whuxlm!whuxl!houxm!ihnp4!plus5!max
  2. From: max@plus5.UUCP (R. Max Mutrux)
  3. Subject: Amiga <-> IBM transfers (A fast System)
  4. Date: 21 Dec 85 08:40:20 GMT
  5. Organization: Plus Five Computer Services, St. Louis
  6.  
  7. Say ALL you amiga developers using PC's as a cross system.  Tired of
  8. waiting around for your 9600 baud transfers to complete.  Well here's
  9. a quick and dirty set of programs that will send files from the PC
  10. to the AMIGA over the parallel interface.  First build a cable like
  11. this:
  12.  
  13.         DB25 Male   DB25 Female
  14.         PC          AMIGA
  15.         ---------   -----------
  16.   -STROBE   1 ......... 13  SEL
  17.        D0   2 .........  2  D0
  18.        D1   3 .........  3  D1
  19.        D2   4 .........  4  D2
  20.        D3   5 .........  5  D3
  21.        D4   6 .........  6  D4
  22.        D5   7 .........  7  D5
  23.        D6   8 .........  8  D6
  24.        D7   9 .........  9  D7
  25.      -ACK  10 ......... 11  BUSY
  26.  -SLCT IN  17 ......... 12  POUT
  27.       GND  18 ......... 18  GND
  28.       GND  19 ......... 19  GND
  29.       GND  20 ......... 20  GND
  30.       GND  21 ......... 21  GND
  31.       GND  22 ......... 22  GND
  32.       GND  23 ......... 14  GND
  33.       GND  24 ......... 15  GND
  34.       GND  25 ......... 16  GND
  35.  
  36. * YOU DON'T REALLY NEED MORE THAN ONE GROUND BUT HOOK UP AS MANY AS POSSIBLE
  37.  
  38. Then Compile TOA.C on the IBM (Microsoft C) and FIBM.C on the Amiga,
  39. hookem up.
  40.  
  41. To Transfer:
  42. IBM:    C> TOA FILENAME
  43.  
  44. AMIGA:
  45.         1> FIBM
  46.  
  47. * THE ORDER OF THESE COMMANDS DOES NOT MATTER ONE WILL ALWAYS WAIT FOR THE
  48.   OTHER
  49.  
  50. FIBM has no options.
  51. These are the options for TOA:
  52.         -b        Send following files binary (no translations)
  53.         -a        Send following files ascii (\n\r to \n, strip ^Z)
  54.         -d<dev>   Add <dev> to the begining of the file name.
  55.                   Useful as -dRAM: to send straight to the ram disk
  56.         -p{0|1}   Select Printer Port 0 or 1 (not tested)
  57.         -h        Hang on. Don't send EOT to amiga.  Usefull if you want
  58.                   to send several batchs of files
  59.  
  60. The Micro Emacs binary took 198 seconds with 9600 baud rs232.
  61. With a parallel connections it took 13 seconds. Also you can transfer
  62. to disk directly instead of going through the ram disk.
  63. TOA can send as many files as you can fit on a command line.  FIBM will
  64. wait for an end of transmition char before exiting.  
  65.  
  66. I'm sure this program will come back to me across the net with all sorts
  67. of spiffy enhancements but this ain't bad for an evenings work (play?).
  68.  
  69. This is Public Domain you can do anything you wan't with it as long as you
  70. keep my name in the source (ego?) and don't get any bucks for it.
  71.  
  72. Two Final Notes:
  73.  
  74. 1)      This thing really eats up the cpu time.  I would try running it in
  75.         the background (the price you pay for speed).
  76.  
  77. 2)      If any Amiga Hardware hack at Commodore read this. Tell me if I'm
  78.         doing anything wrong by reversing the direction on the parallel
  79.         port
  80.  
  81. -------------------------------TOA.C (for IBM)-------------------------------
  82. /*
  83.  
  84.                         TOA     -       Transfer files to an Amiga via Parallel connection
  85.                                 
  86.         Edit History:
  87.         R. Max Mutrux   21-DEC-85       V1.0    Gee It Works(?)
  88.                 
  89. */
  90. #include <stdio.h>
  91. #include <fcntl.h>
  92.  
  93. char    aton[32];                               /* Device Added to name before opening (Remote) */
  94. char    sname[64];                              /* final transmitted name */
  95. int     f_binary = 1;                   /* binary flag */
  96. int     f_hold = 0;                             /* hold flag */
  97. int     devbase = 0x278;                /* Parallel Printer Port */
  98.  
  99. int     reg_data = 0x278;
  100. int     reg_ctrl = 0x27a;
  101. int     reg_status = 0x279;
  102. main(ac,av)
  103. int ac;
  104. char *av[];
  105. {
  106.         int i;
  107.         int j;
  108.         char *fstrip();
  109.  
  110.         if(ac<2) {
  111.                 printf("Usage: toa [-{b|a}] [-ddevice] [-p{0|1}] [-h] file [file...]\n");
  112.                 exit(1);
  113.         }
  114.         aton[0] = 0;
  115.         for(i=1; i<ac; i++) {
  116.                 if(av[i][0]=='-') {
  117.                         switch(av[i][1]) {
  118.                         case 'b': case 'B':     /* Binary */
  119.                                 f_binary = 1;
  120.                                 continue;
  121.                         case 'a': case 'A':     /* Ascii */
  122.                                 f_binary = 0;
  123.                                 continue;
  124.                         case 'd': case 'D':     /* Device (Destination) */
  125.                                 strcpy(aton,&av[i][2]);
  126.                                 continue;
  127.                         case 'p': case 'P':
  128.                                 if(av[i][2]=='2')
  129.                                         devbase = 0x378;
  130.                                 else
  131.                                         devbase = 0x278;
  132.                                 reg_data = devbase;
  133.                                 reg_ctrl = devbase+2;
  134.                                 reg_status = devbase+1;
  135.                                 continue;
  136.                         case 'h': case 'H':
  137.                                 f_hold = 1;
  138.                                 continue;
  139.                         default:
  140.                                 printf("-%c  Huh?\n",av[i][1]);
  141.                         }
  142.                 }
  143.                 if(f_binary)
  144.                         j = open(av[i],O_RDONLY|O_BINARY);
  145.                 else
  146.                         j = open(av[i],O_RDONLY|O_TEXT);
  147.                 sprintf(sname,"%s%s",aton,fstrip(av[i]));
  148.                 if(j>0) {
  149.                         printf("SEND: \"%s\" as \"%s\" ",av[i],sname);
  150.                         transmit(j,sname);
  151.                         close(j);
  152.                         printf("Done\n");
  153.                 }
  154.         }
  155.         if(f_hold==0)
  156.                 sendbyte(0x1ff);                /* send end of transmition special char */
  157. }
  158.  
  159. char *fstrip(s)
  160. register char *s;
  161. {
  162.         register int l;
  163.         l = strlen(s) - 1;
  164.         for(;l>=0;--l) {
  165.                 if(s[l]==':' || s[l]=='\\' || s[l]=='/')
  166.                         break;
  167.         }
  168.         return &s[l+1];
  169. }
  170.         
  171. transmit(fd,na)
  172. int fd;
  173. char *na;
  174. {
  175.         char block[512];
  176.         int l;
  177.         sendbyte(0x100);                        /* send start of name special char */
  178.         sendblock(na,strlen(na));
  179.         sendbyte(0x101);                        /* send start of data special char */
  180.         while((l=read(fd,block,512))!=0)
  181.                 sendblock(block,l);
  182.         sendbyte(0x1fe);                        /* send end of data special char */
  183. }
  184.  
  185. sendblock(b,l)
  186. register unsigned char *b;
  187. register int l;
  188. {
  189.         while(--l >=0 )
  190.                 sendbyte(*b++);
  191. }
  192.  
  193. sendbyte(c)
  194. register int c;
  195. {
  196.         register i7a;
  197.         i7a = 0;
  198.         outp(reg_data,c&255);                           /* assert byte onto data pins */
  199.         if(c>255)
  200.                 i7a = 8;                                                                /* if special char (C)*/
  201.         else
  202.                 i7a = 0;                                                                /* if data char (D)*/
  203.         outp(reg_ctrl,1|i7a);                           /* assert DAV and C/D */
  204.         while(inp(reg_status)&0x40) ;           /* wait for ACK asserted*/
  205.         outp(reg_ctrl,0);                                               /* negate DAV and C/D */
  206.         while((inp(reg_status)&0x40)==0) ; /* wait for ACK negated */
  207. }
  208.  
  209. -----------------------------FIBM.C (for Amiga)------------------------------
  210. /*
  211.  
  212.                         FIBM    -       Receive files from an IBM via Parallel connection
  213.                                 
  214.         Edit History:
  215.         R. Max Mutrux   21-DEC-85       V1.0    Boy this Amiga is slick
  216.                 
  217. */
  218. #include <stdio.h>
  219.  
  220. #define STATE_NULL      0       /* THROW OUT DATA */
  221. #define STATE_NAME      1       /* RECEIVE NAME */
  222. #define STATE_DATA      2       /* RECEIVE DATA */
  223.  
  224. main()
  225. {
  226.         register unsigned char *dataport;
  227.         register unsigned char *ctrlport;
  228.         unsigned char *datadirport;
  229.         unsigned char *ctrldirport;
  230.         unsigned char origdatadir;
  231.         unsigned char origctrldir;
  232.         register unsigned int c;
  233.         register unsigned int state;
  234.         register unsigned int block_len;
  235.         register unsigned long filep;
  236.         register int i;
  237.         char    block[512];
  238.         dataport = (char *)0xbfe101;
  239.         datadirport = (char *)0xbfe301;
  240.  
  241.         ctrlport = (char *)0xbfd000;
  242.         ctrldirport = (char *)0xbfd200;
  243.  
  244.         origdatadir = *datadirport;
  245.         origctrldir = *ctrldirport;
  246.         *datadirport = 0x00;
  247.         *ctrldirport |= 0x01;
  248.  
  249.         state = 0;
  250.         filep = 0;
  251.         block_len = 0;
  252.  
  253.         for(;;) {
  254.                 while((*ctrlport&0x04)) ;
  255.                 c = *ctrlport & 0x02;
  256.                 if(!c)
  257.                         c = 0x100;
  258.                 else
  259.                         c = 0;
  260.                 c |= *dataport;
  261.                 *ctrlport &= ~1;
  262.                 while((*ctrlport&0x04)==0) ;
  263.                 *ctrlport |= 1;
  264.                 if(c<0x100) {
  265.                         if(state==STATE_NAME) {
  266.                                 if(block_len>30)
  267.                                         continue;
  268.                                 block[block_len++] = c;
  269.                         } else {
  270.                                 if(state==STATE_DATA) {
  271.                                         if(block_len>511) {
  272.                                                 if(Write(filep,block,block_len)<0) {
  273.                                                         printf("write error %d\n",IoErr());
  274.                                                         Close(filep);
  275.                                                         state = STATE_NULL;
  276.                                                 }
  277.                                                 block_len = 0;
  278.                                         }
  279.                                         block[block_len++] = c;
  280.                                 }
  281.                         }
  282.                 } else {
  283.                         switch(c-0x100) {
  284.                         case 0x00:      /* START OF FILE NAME */
  285.                                 block_len = 0;
  286.                                 state = STATE_NAME;
  287.                                 continue;
  288.                         case 0x01:      /* START OF DATA FOR FILE */
  289.                                 block[block_len++] = 0;
  290.                                 block_len = 0;
  291.                                 printf("REC: \"%s\" ",block);
  292.                                 filep = Open(block,1006);
  293.                                 if(filep==0L) {
  294.                                         i = IoErr();
  295.                                         printf("open error %d\n",i);
  296.                                         state = STATE_NULL;
  297.                                         continue;
  298.                                 }
  299.                                 state = STATE_DATA;
  300.                                 continue;
  301.                         case 0xfe:      /* END OF FILE */
  302.                                 if(state==STATE_DATA) {
  303.                                         if(block_len>0) {
  304.                                                 if(Write(filep,block,block_len)<0)
  305.                                                         printf("Write Error %d\n",IoErr());
  306.                                                 else
  307.                                                         printf("OK\n");
  308.                                         } else
  309.                                                 printf("OK\n");
  310.                                         Close(filep);
  311.                                 }
  312.                                 state = STATE_NULL;
  313.                                 continue;
  314.                         case 0xff:      /* END OF TRANSMITTION */
  315.                                 printf("EOT\n");
  316.                                 exit(1);
  317.                         }
  318.                 }
  319.         }
  320. }
  321.